import { HElement } from "../libs/HElement";

export const Prop = <K extends keyof HElement>(elementQuery: string, prop: K): PropertyDecorator => {
    const el: any = document.querySelector(elementQuery);
    return (target: any, propertyKey: string | symbol) => {
        if (el === null) return;
        delete target[propertyKey];
        const getter = function (this: any) {
            return el[prop];
        }
        const setter = function (this: any, newVal: any) {
            el[prop] = newVal;
        }
        Object.defineProperty(target, propertyKey, {
            enumerable: true,
            configurable: false,
            set: setter,
            get: getter,
        });
    }
}